import type { FormSchemaGetter, VbenFormSchema } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { z } from '#/adapter/form';
import { renderDictTag } from '#/utils/render';

/**
 * 医院等级选项
 */
export const levelOptions = [
  {
    label: '一级',
    value: 1,
    dictLabel: '一级',
    dictValue: 1,
  },
  {
    label: '二级',
    value: 2,
    dictLabel: '二级',
    dictValue: 2,
  },
  {
    label: '三级',
    value: 3,
    dictLabel: '三级',
    dictValue: 3,
  },
];

export const querySchema: FormSchemaGetter = () => [
  // {
  //   component: 'Input',
  //   fieldName: 'hospitalName',
  //   label: '医院名称',
  // },
];

export const columns: VxeGridProps['columns'] = [
  {
    title: '医院名称',
    field: 'hospitalName',
  },
  {
    title: '医院电话',
    field: 'telephone',
  },
  {
    field: 'hospitalImg',
    title: '医院图片',
    slots: { default: 'hospitalImg' },
    minWidth: 80,
  },
  {
    title: '医院等级',
    field: 'level',
    slots: {
      default: ({ row }) => {
        return renderDictTag(row.level, levelOptions);
      },
    },
  },
  {
    title: '医院地址',
    field: 'address',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

export const modalSchema = (
  handleUpload: (file: File) => void,
  handleRemove: () => void,
): VbenFormSchema[] => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
    label: '医院ID',
  },
  {
    component: 'Upload',
    componentProps: {
      // 更多属性见：https://ant.design/components/upload-cn
      accept: '.png,.jpg,.jpeg',
      // 自动携带认证信息
      // customRequest: uploadApi,
      disabled: false,
      maxCount: 1,
      multiple: false,
      showUploadList: true,
      // 上传列表的内建样式，支持四种基本样式 text, picture, picture-card 和 picture-circle
      listType: 'picture-card',
      beforeUpload: (file: File) => {
        handleUpload(file);
        return false;
      },
      onRemove: (_file: File) => {
        handleRemove();
      },
    },
    fieldName: 'hospitalImg',
    label: '医院图片',
    renderComponentContent: () => {
      return {
        default: () => '上传图片',
      };
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'hospitalName',
    label: '医院名称',
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'telephone',
    label: '医院电话',
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'level',
    label: '医院等级',
    defaultValue: 3,
    componentProps: {
      options: levelOptions,
      placeholder: '请选择医院等级',
    },
    rules: z.number().min(1, { message: '请选择医院等级' }),
  },
  {
    component: 'Input',
    fieldName: 'address',
    label: '医院地址',
    rules: 'required',
  },
];
